package com.aliang.shopping.model.converter;

import com.aliang.shopping.model.enums.UserTypeEnum;
import com.aliang.shopping.model.vo.operationLog.OperationLogExportVO;
import com.aliang.shopping.model.vo.operationLog.OperationLogVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;
import java.util.Objects;

/**
 * 登录日志数据转换器
 */
@Mapper(componentModel = "Spring")
public interface OperationLogConverter {


    /**
     * 将登录日志展示对象转换为登录日志导出对象
     *
     * @param vo
     * @return
     */
    @Mappings({
            @Mapping(target = "errorMsg", defaultValue = "无"),
            @Mapping(target = "personType", expression = "java(getPersonTypeMsg(vo.getPersonType()))"),
            @Mapping(target = "status", expression = "java(CommonConverter.getMsg(vo.getStatus(),\"操作成功\",\"操作失败\"))"),
    })
    OperationLogExportVO toExportVO(OperationLogVO vo);

    List<OperationLogExportVO> toImportDTOList(List<OperationLogVO> list);

    default String getPersonTypeMsg(Integer type) {

        if (Objects.equals(type, UserTypeEnum.USER.getCode())) {
            return "用户";
        }
        if (Objects.equals(type, UserTypeEnum.BUSINESS.getCode())) {
            return "商家";
        }
        if (Objects.equals(type, UserTypeEnum.ADMIN.getCode())) {
            return "管理员";
        }
        if (Objects.equals(type, UserTypeEnum.SUPER_ADMIN.getCode())) {
            return "超级管理员";
        }
        return "未知";
    }
}
